package org.elanfox.cloud.mybatis.ddl;

import org.elanfox.cloud.mybatis.base.MybatisProperties;
import org.elanfox.cloud.mybatis.ddl.service.SqlDDLService;
import org.elanfox.cloud.mybatis.utils.EntityHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author allan
 * @version 1.0.0
 * @date 2021/4/21
 */
@Component
public class DDLStart {
    @Autowired
    private SqlDDLService ddlService;
    @Autowired
    private MybatisProperties properties;

    @PostConstruct
    public void start() {
        switch (properties.getDdlAuto()) {
            case "create":
                ddlService.create();
                break;
            case "drop-create":
                ddlService.dropAndCreate();
                break;
            case "update":
                ddlService.update();
                break;
            case "validate":
                ddlService.validate();
                break;
            default:
                break;
        }

        //手动释放一下空间
        EntityHelper.release();
        System.gc();
    }
}
